﻿#region zh-CHS 2006 - 2008 DemoSoft 团队 | en 2006 - 2008 DemoSoft Team

//     NOTES
// ---------------
//
// This file is a part of the MMOSE(Massively Multiplayer Online Server Engine) for .NET.
//
//                              2006-2008 DemoSoft Team
//
//
// First Version : by H.Q.Cai - mailto:caihuanqing@hotmail.com

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published
 *   by the Free Software Foundation; either version 2.1 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

#region zh-CHS 包含名字空间 | en Include namespace
using System;
using System.Runtime.InteropServices;
using Demo.Mmose.Core.Common;
#endregion

namespace Demo.Mmose.Misc.Net.Dll
{
    /// <summary>
    /// 网络的数据包
    /// </summary>
    [MultiThreadedNoSupport( "zh-CHS", "当前的类所有成员没有锁定(仅支持局部操作),不支持多线程操作" )]
    public class MessageBlock
    {
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 网络的数据包的指针
        /// </summary>
        private IntPtr m_Value  = IntPtr.Zero;
        #endregion

        #region zh-CHS 共有属性 | en Public Properties
        /// <summary>
        /// 数据已经读取的长度
        /// </summary>
        public int ReadLength
        {
            get { return MessageBlock.MessageBlock_ReadLength( m_Value ); }
        }

        /// <summary>
        /// 数据已经写入的长度
        /// </summary>
        public int WriteLength
        {
            get { return MessageBlock.MessageBlock_WriteLength( m_Value ); }
        }

        /// <summary>
        /// 数据包的长度
        /// </summary>
        public int Length
        {
            get { return MessageBlock.MessageBlock_Length( m_Value ); }
        }

        /// <summary>
        /// 缓冲区的数据大小
        /// </summary>
        public int Size
        {
            get { return MessageBlock.MessageBlock_Size( m_Value ); }
        }
        #endregion

        #region zh-CHS 共有方法 | en Public Methods
        /// <summary>
        /// 数据包的基指针
        /// </summary>
        /// <returns></returns>
        public IntPtr BasePointer()
        {
            return MessageBlock.MessageBlock_BasePointer( m_Value );
        }

        /// <summary>
        /// 数据包的读指针
        /// </summary>
        /// <returns></returns>
        public IntPtr ReadPointer()
        {
            return MessageBlock.MessageBlock_ReadPointer( m_Value );
        }

        /// <summary>
        /// 数据包的写指针
        /// </summary>
        /// <returns></returns>
        public IntPtr WritePointer()
        {
            return MessageBlock.MessageBlock_WritePointer( m_Value );
        }

        /// <summary>
        /// 数据包的读指针的位置
        /// </summary>
        /// <param name="readLength"></param>
        public void ReadPointer(int readLength)
        {
            MessageBlock.MessageBlock_ReadPointerLength( readLength, m_Value );
        }

        /// <summary>
        /// 数据包的写指针的位置
        /// </summary>
        /// <param name="writeLength"></param>
        public void WritePointer(int writeLength)
        {
            MessageBlock.MessageBlock_WritePointerLength( writeLength, m_Value );
        }

        /// <summary>
        /// 数据包的指针复原位置
        /// </summary>
        public void ResetPointer()
        {
            MessageBlock.MessageBlock_ResetPointer( m_Value );
        }
        #endregion

        #region zh-CHS 内部属性 | en Internal Properties
        /// <summary>
        /// 网络的数据包的指针
        /// </summary>
        protected internal IntPtr Value
        {
            get { return m_Value; }
            set { m_Value = value; }
        }
        #endregion

        #region zh-CHS 引入DLL接口 | en DLL Import
        /// <summary>
        /// dll 调用
        /// </summary>
        /// <param name="pMessageBlock"></param>
        /// <returns></returns>
        [DllImport("Demo.Mmose.Net.dll", CallingConvention = CallingConvention.StdCall)]
        private static extern IntPtr MessageBlock_BasePointer(IntPtr pMessageBlock);

        /// <summary>
        /// dll 调用
        /// </summary>
        /// <param name="pMessageBlock"></param>
        /// <returns></returns>
        [DllImport("Demo.Mmose.Net.dll", CallingConvention = CallingConvention.StdCall)]
        private static extern IntPtr MessageBlock_ReadPointer(IntPtr pMessageBlock);

        /// <summary>
        /// dll 调用
        /// </summary>
        /// <param name="pMessageBlock"></param>
        /// <returns></returns>
        [DllImport("Demo.Mmose.Net.dll", CallingConvention = CallingConvention.StdCall)]
        private static extern IntPtr MessageBlock_WritePointer(IntPtr pMessageBlock);

        /// <summary>
        /// dll 调用
        /// </summary>
        /// <param name="readLength"></param>
        /// <param name="pMessageBlock"></param>
        [DllImport("Demo.Mmose.Net.dll", CallingConvention = CallingConvention.StdCall)]
        private static extern void MessageBlock_ReadPointerLength(int readLength, IntPtr pMessageBlock);

        /// <summary>
        /// dll 调用
        /// </summary>
        /// <param name="writeLength"></param>
        /// <param name="pMessageBlock"></param>
        [DllImport("Demo.Mmose.Net.dll", CallingConvention = CallingConvention.StdCall)]
        private static extern void MessageBlock_WritePointerLength(int writeLength, IntPtr pMessageBlock);

        /// <summary>
        /// dll 调用
        /// </summary>
        /// <param name="pMessageBlock"></param>
        [DllImport("Demo.Mmose.Net.dll", CallingConvention = CallingConvention.StdCall)]
        private static extern void MessageBlock_ResetPointer(IntPtr pMessageBlock);

        /// <summary>
        /// dll 调用
        /// </summary>
        /// <param name="pMessageBlock"></param>
        /// <returns></returns>
        [DllImport("Demo.Mmose.Net.dll", CallingConvention = CallingConvention.StdCall)]
        private static extern int MessageBlock_ReadLength(IntPtr pMessageBlock);

        /// <summary>
        /// dll 调用
        /// </summary>
        /// <param name="pMessageBlock"></param>
        /// <returns></returns>
        [DllImport("Demo.Mmose.Net.dll", CallingConvention = CallingConvention.StdCall)]
        private static extern int MessageBlock_WriteLength(IntPtr pMessageBlock);

        /// <summary>
        /// dll 调用
        /// </summary>
        /// <param name="pMessageBlock"></param>
        /// <returns></returns>
        [DllImport("Demo.Mmose.Net.dll", CallingConvention = CallingConvention.StdCall)]
        private static extern int MessageBlock_Length(IntPtr pMessageBlock);

        /// <summary>
        /// dll 调用
        /// </summary>
        /// <param name="pMessageBlock"></param>
        /// <returns></returns>
        [DllImport("Demo.Mmose.Net.dll", CallingConvention = CallingConvention.StdCall)]
        private static extern int MessageBlock_Size(IntPtr pMessageBlock);
        #endregion
    }
}
#endregion

